package cn.tedu.staff_user.management.controller;

import cn.tedu.common.pojo.po.StaffSearchPO;
import cn.tedu.common.web.JsonResult;
import cn.tedu.staff_user.management.pojo.entity.Staff;
import cn.tedu.staff_user.management.pojo.param.StaffAddNewParam;
import cn.tedu.staff_user.management.pojo.param.StaffUpdateParam;
import cn.tedu.staff_user.management.pojo.vo.StaffListItemVO;
import cn.tedu.staff_user.management.service.IStaffService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "1.员工管理")
@RestController
@RequestMapping("/staffs")
public class StaffController {

    @Autowired
    private IStaffService staffService;

    @GetMapping("/1")
    @ApiOperation("员工列表1")
    @ApiOperationSupport(order = 401)
    public JsonResult listAdmin1(String username){

        final List<StaffSearchPO> staffSearchPOS = staffService.listSearch(username);

        return JsonResult.ok(staffSearchPOS);
    }


    @GetMapping("")
    @ApiOperation("员工列表")
    @ApiOperationSupport(order = 400)
    public JsonResult listAdmin(){

        List<StaffListItemVO> list = staffService.list();

        return JsonResult.ok(list);
    }

    @PostMapping("/add-new")
    @ApiOperation("添加员工")
    @ApiOperationSupport(order = 410)
    public JsonResult addNew(StaffAddNewParam staffAddNewParam){
        staffService.addNew(staffAddNewParam);
        return JsonResult.ok();
    }

    @PostMapping("/{id}/delete")
    @ApiOperation("删除员工")
    @ApiOperationSupport(order = 420)
    public JsonResult deleteById(@PathVariable Long id){
        staffService.deleteById(id);
        return JsonResult.ok();
    }

    @PostMapping("/update")
    @ApiOperation("更新员工")
    @ApiOperationSupport(order = 420)
    public JsonResult updateById(StaffUpdateParam staffUpdateParam){
        staffService.updateById(staffUpdateParam);
        return JsonResult.ok();
    }


    @PostMapping("/{id}/setEnable")
    // @PreAuthorize("hasAuthority('/content/comment/simple')")
    @ApiOperation("修改为优秀员工")
    @ApiOperationSupport(order = 312)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "员工ID", required = true, dataType = "long")
    })
    public JsonResult setEnable(@PathVariable @Range(min = 1, message = "请提交有效的员工ID值！") Long id) {
        log.debug("开始处理【显示评论】的请求，参数：{}", id);
        staffService.setEnable(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id}/disable")
    //  @PreAuthorize("hasAuthority('/content/comment/simple')")
    @ApiOperation("修改为非优秀员工")
    @ApiOperationSupport(order = 313)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "员工ID", required = true, dataType = "long")
    })
    public JsonResult disable(@PathVariable @Range(min = 1, message = "请提交有效的员工ID值！") Long id) {
        log.debug("开始处理【隐藏评论】的请求，参数：{}", id);
        staffService.disable(id);
        return JsonResult.ok();
    }


    /**
     * 查看优秀员工接口
     */

    @PostMapping("/list")
    //  @PreAuthorize("hasAuthority('/content/comment/simple')")
    @ApiOperation("查看优秀员")
    @ApiOperationSupport(order = 315)
    public JsonResult list() {
        log.debug("开始处理【查看优秀员】的请求，参数：{}");
        List<StaffListItemVO> staffListItemVOS = staffService.selectList();
        return JsonResult.ok(staffListItemVOS);
    }
}
